package com.le.edu.controller;

import com.le.edu.domain.entity.Section;
import com.le.edu.resp.Result;
import com.le.edu.service.SectionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author Le
 * @create 2024-04-10 16:14
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "课时接口")
@RequestMapping("/section")
public class SectionController extends BaseController {
    private final SectionService sectionService;

    @Operation(summary = "添加课时")
    @PostMapping
    public Result<Void> addSection(@RequestBody Section section) {
        return toAjax(sectionService.save(section));
    }

    @Operation(summary = "修改课时")
    @PutMapping
    public Result<Void> updateSection(@RequestBody Section section) {
        return toAjax(sectionService.updateById(section));
    }

    @Operation(summary = "删除课时")
    @PostMapping("/delSection")
    public Result<Void> delSection(@RequestBody Section section) {
        sectionService.removeSectionAndVideo(section.getSectionId(), section.getVideoId());
        return Result.ok();
    }
}
